<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Main extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->library('parser');
        $this->load->model('hostjogja');
    }

    function index() {
        $this->load->view('main');
    }

    function login() {
        $this->form_validation->set_rules('username', 'required');
        $this->form_validation->set_rules('password', 'required');
        if ($this->form_validation->run() == FALSE) {
            redirect('main');
        } else {
            $input = array(
                'username' => $this->input->post('username'),
                'password' => $this->encrypt->sha1($this->input->post('password'))
            );
            $login = $this->hostjogja->login($input); //kirim ke database
            if ($login->previlege_id != NULL) {
                $ses = array(
                    'username' => $login->username,
                    'login' => TRUE,
                    'privilege' => $login->previlege_id
                );
                $this->session->set_userdata($ses);
                redirect('admin');
            } else {
                redirect('main');
            }
        }
    }

    function logout() {
        $this->session->sess_destroy();
        redirect();
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/main.php */